/****************************************************************************/    
/* NAME:           Hal_TimerManagement.c                                    */    
/* PURPOSE:        Manage all virtual timer                                 */    
/* CREATED_BY:     Vyx                                                      */    
/* CREATION_DATE:  03/07/2012                                               */ 
/************************************** (C) Copyright 2012 AquaLink *********/

#include "HAL_TimerManagement.h"


/**        
  * @brief  Get if timer is reached the max value         
  * @param  Timer name        
  * @retval None        
  */ 
bool TIMER_GetIsToReached(TimerList_def_t TimerName)
{
  return (TimerConfigList[TimerName].ToReached;)
}

/**        
  * @brief  Init and start a timer         
  * @param  Timer name, Max value to be reached        
  * @retval None        
  */ 
void TIMER_StartTimer(TimerList_def_t TimerName, uint32_t MaxValue)
{
  TimerConfigList[TimerName].Active    = TRUE;
  TimerConfigList[TimerName].ToReached = FALSE;
  TimerConfigList[TimerName].Max       = MaxValue;
  TimerConfigList[TimerName].Count     = 0;   
}

/**        
  * @brief  Stop a timer
  * @param  Timer name        
  * @retval None        
  */ 
void TIMER_StopTimer(TimerList_def_t TimerName)
{
  TimerConfigList[TimerName].Active    = FALSE;
  TimerConfigList[TimerName].ToReached = FALSE;
  TimerConfigList[TimerName].Max       = 0;
  TimerConfigList[TimerName].Count     = 0;     
}

/**        
  * @brief  Reset a timer         
  * @param  Timer name       
  * @retval None        
  */ 
void TIMER_ResetTimer(TimerList_def_t TimerName)
{
  TimerConfigList[TimerName].ToReached = FALSE;
  TimerConfigList[TimerName].Count     = 0;     
}

/**        
  * @brief  Function for increment counter (call in systick)         
  * @param  None        
  * @retval None        
  */  
void TIMER_IncrementAllTimer()
{
  uint8_t TimerName;
  
  for (TimerName=0; TimerName<TIMER_NUMBER; TimerName++)
  {
    if (TimerConfigList[TimerName].Count < TimerConfigList[TimerName].Max)
    {
      TimerConfigList[TimerName].Count++;  
    }
    else
    {
      TimerConfigList[TimerName].ToReached = TRUE;
    }
  }
}
